

from flask import Blueprint, jsonify, request
from App.models.db_models import Topic
from App.models._models import  close
from App.models.practice_models import  select
practice = Blueprint('practice', __name__, url_prefix="/practice")


@practice.route('', methods=['POST'])
def practice_():
    tyPe = request.json.get('type')
    yeAr = request.json.get('year')
    if yeAr ==None and tyPe==None:
        p = Topic.query.all()
    elif yeAr==None:
        p = Topic.query.filter_by(type=tyPe).all()
    elif tyPe==None:
        p = Topic.query.filter_by(year=yeAr).all()
    else:
        p=Topic.query.filter_by(year=yeAr,type=tyPe).all()

    c=select(p)
    close()
    return jsonify(c)
